package com.smarthealthcare.cost.service.impl;

import java.util.List;
import java.util.UUID;

import com.smarthealthcare.common.utils.DateUtils;
import com.smarthealthcare.mapper.RegisterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smarthealthcare.cost.mapper.CostMapper;
import com.smarthealthcare.cost.domain.Cost;
import com.smarthealthcare.cost.service.ICostService;

/**
 * 费用列表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-25
 */
@Service
public class CostServiceImpl implements ICostService 
{
    @Autowired
    private CostMapper costMapper;
    @Autowired
    private RegisterMapper registerMapper;

    /**
     * 查询费用列表
     * 
     * @param id 费用列表主键
     * @return 费用列表
     */
    @Override
    public Cost selectCostById(Long id)
    {
        Cost cost = costMapper.selectCostById(id);
        cost.setRegister(registerMapper.selectRegisterById(cost.getPatientId()));
        return cost;
    }

    /**
     * 查询费用列表列表
     * 
     * @param cost 费用列表
     * @return 费用列表
     */
    @Override
    public List<Cost> selectCostList(Cost cost)
    {
        List<Cost> costs = costMapper.selectCostList(cost);
        for (Cost c : costs){
            c.setRegister(registerMapper.selectRegisterById(c.getPatientId()));
        }
        return costs;
    }

    /**
     * 新增费用列表
     * 
     * @param cost 费用列表
     * @return 结果
     */
    @Override
    public int insertCost(Cost cost)
    {
        cost.setCreateTime(DateUtils.getNowDate());
        cost.setCostNum(UUID.randomUUID().toString().substring(0,8));
        return costMapper.insertCost(cost);
    }

    /**
     * 修改费用列表
     * 
     * @param cost 费用列表
     * @return 结果
     */
    @Override
    public int updateCost(Cost cost)
    {
        return costMapper.updateCost(cost);
    }

    /**
     * 批量删除费用列表
     * 
     * @param ids 需要删除的费用列表主键
     * @return 结果
     */
    @Override
    public int deleteCostByIds(Long[] ids)
    {
        return costMapper.deleteCostByIds(ids);
    }

    /**
     * 删除费用列表信息
     * 
     * @param id 费用列表主键
     * @return 结果
     */
    @Override
    public int deleteCostById(Long id)
    {
        return costMapper.deleteCostById(id);
    }

    @Override
    public int deleteCostByParentId(Integer parentId) {
        return costMapper.deleteCostByParentId(parentId);
    }
}
